﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.FileLayer;

namespace HA.ModFlow.Domain.DomainLayer
{
    [Serializable]
    public class DESolver : ICloneable
    {
        int _ITMX = 1;

        /// <summary>
        /// 每次时间循环的最大迭代次数
        /// </summary>
        public int ITMX
        {
            get { return _ITMX; }
            set { _ITMX = value; }
        }
        private bool _ITMXb = true  ;
        /// <summary>
        /// 是否需要迭代,默认不迭代
        /// </summary>
        public bool ITMXb
        {
            get { return _ITMXb; }
            set { _ITMXb = value; }
        }

        int _MAXUP = 0;
        /// <summary>
        /// 在upper part of the equations用于解法的最大方程数量
        /// </summary>
        public int MAXUP
        {
            get { return _MAXUP; }
            set { _MAXUP = value; }
        }

        int _MXLOW = 0;
        /// <summary>
        /// 在lower part of the equations用于解法的最大方程数量
        /// </summary>
        public int MXLOW
        {
            get { return _MXLOW; }
            set { _MXLOW = value; }
        }

        double _MXBW = 1;

        /// <summary>
        /// 最大频带宽度，AL乘以1
        /// </summary>
        public double MXBW
        {
            get { return _MXBW; }
            set { _MXBW = value; }
        }


        int _IFREQ = 1;

        /// <summary>
        /// 表明频率系数变化标志
        /// </summary>
        public int IFREQ
        {
            get { return _IFREQ; }
            set { _IFREQ = value; }
        }


        int _MUTD4;

        /// <summary>
        /// 输出控制,MUTD4=0，补偿的迭代次数和每次迭代最大水头变化输出
        /// MUTD4=1，仅输出步长的迭代次数
        ///MUTD4=2，不打印任何信息
        /// </summary>
        public int MUTD4
        {
            get { return _MUTD4; }
            set { _MUTD4 = value; }
        }

        double _ACCL = 1;
        /// <summary>
        /// 迭代计算水头变化的乘数因子
        /// </summary>
        public double ACCL
        {
            get { return _ACCL; }
            set { _ACCL = value; }
        }

        double _HCLOSE = 1;
        /// <summary>
        /// 水头变化闭合准则
        /// </summary> 
        public double HCLOSE
        {
            get { return _HCLOSE; }
            set { _HCLOSE = value; }
        }

        int _IPRD4 = 1;
        /// <summary>
        /// 仅在使用迭代时（ITMX>1），使用。任何情况都需写入到inp文件。打印输出间隔
        /// </summary>
        public int IPRD4
        {
            get { return _IPRD4; }
            set { _IPRD4 = value; }
        }



        public PDirectSolver ToPack()
        {
            PDirectSolver pds = new PDirectSolver();

            pds.ITMX = this.ITMX;
            pds.MAXUP = this.ITMX;
            pds.MXLOW = this.MXLOW;
            pds.MXBW = this.MXBW;
            //在不迭代的情况下为1,2,在迭代的情况下为3
            if (this.ITMXb)
            {
                pds.IFREQ = this.IFREQ;
            }
            else
            {
                pds.IFREQ = 3;
            }
          
            pds.MUTD4 = this.MUTD4;
            //正常情况下，此值为1；当只大于1时，
            // 在使用外不迭代解决非线性问题提供收敛比率时很有用。
            //ACCL对于线性问题来说应该是1.。当ITMX=1时，ACCL变为1，而不管其输入的数值。
            if (this.ITMX == 1)
            {
                this.ACCL = 1;
            }
            pds.ACCL = this.ACCL;
            pds.HCLOSE = this.HCLOSE;
            pds.IPRD4 = this.IPRD4;
            return pds;

        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }

    }
}
